<?php 
class Articles extends E_Entity 
{
	public   $table =array(
					"id" =>"id",
					"version"=>"version",
					"directoryid"=>"directoryid",
					"multdirectoryid"=>"multdirectoryid",
					"title" =>"title",
					"coverimage" =>"coverimage",
					"allimage" =>"allimage",
					"source" =>"source",
					"author" =>"author",
					"intro" =>"intro",
					"content"=>"content",
					"sign" =>"sign",
					"status" =>"status",
					"ctime" =>"ctime",
					"mtime" =>"mtime"
					);
					
	public function getTableName()
	{
		return "articles";
	}
	public function getJoinMap()
	{
		$map = array("mapDirectory" =>array("Entity"=>"Directorys","Method"=>"getById", "param"=>"directoryid"),
					 "mapMultdirectory" =>array("Entity"=>"Multdirectorys","Method"=>"getById", "param"=>"multdirectoryid"),			 
					 "mapMultcomment_num" =>array("Entity"=>"Multcomments","Method"=>"getNum", "param"=>"id")
			);
		return $map;
	}
	public static function insertEntity($row)
	{	
		$entity = new self();
	 	return $entity->createEntityForRow($row);
	}
	public static function getById($id)
	{
		$entity = new self();
		$sql =  "select * from {$entity->getTableName()} where  {$entity->table['id']} = :id";
		return $entity->getEntityByIndexKey($sql, $id, array("id"=>$id));
	}
	public static function getByTitle($title)
	{
		$entity = new self();
		$sql =  "select * from {$entity->getTableName()} where  {$entity->table['title']} = :title";
		return $entity->getEntityByIndexKey($sql, $id, array("title"=>$title));
	}
	public static function getList($where = " 1=1 " ,$limit = '', $order = 'order by ctime desc')
	{
		$entity = new self();
		$sql =  "select * from {$entity->getTableName()} where $where  and  status=1 $order $limit ";
		return $entity->birthEntity($sql);
	}
	public function getMtime()
	{
		return date("Y-m-d H:i:s", $this->mtime);
	}
	public function getCtime($Ymd = "Y-m-d H:i:s")
	{
		return date($Ymd, $this->ctime);
	}
	public function getAllimage()
	{
		$allimage = $this->allimage;
		
		if(!empty($allimage))
		{
			$allimage = substr($allimage,0,-1);
			return explode(",", $allimage);
			 
		}	
		else
		{
			return array();
		}
	}
	public function getCoverimage()
	{
		$coverimage = $this->coverimage;
		if(!empty($coverimage))
		{
			$first_array = explode(".", $coverimage);
			return $first_array[0]."_117X160.".$first_array[1];
			
		}	
		else
		{
			return '';
		}
	}
	public function getContent()
	{
		$content = $this->content;
		return dhtmlspecialchars_decode($content);
	}
}
?>